<?php
declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

final class CreateReviewFeedbackEntityTable extends AbstractMigration
{
    public function up()
    {
        $table = $this->table('review_feedback_entity', ['id' => false, 'primary_key' => ['id'], 'engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '审核反馈实体表']);
        $table->addColumn('id', 'integer', ['identity' => true, 'signed' => false, 'limit' => 11, 'comment' => '主键ID'])
            ->addColumn('review_feedback_id', 'integer', ['limit' => 11, 'default' => 0, 'null' => false, 'comment' => '审核反馈id'])
            ->addColumn('tenant_id', 'integer', ['limit' => 11, 'null' => false, 'signed' => false, 'default' => 0, 'comment' => '租户id'])
            ->addColumn('entity_id', 'integer', ['limit' => 11, 'null' => false, 'signed' => false, 'default' => 0, 'comment' => '实体id'])
            ->addColumn('entity_module_id', 'integer', ['limit' => 11, 'null' => false, 'signed' => false, 'default' => 0, 'comment' => '模块id'])
            ->addColumn('name', 'string', ['default' => '', 'limit' => 128, 'comment' => '名称'])
            ->addColumn('initial_episode_code', 'string', ['default' => '', 'limit' => 128, 'comment' => '初始集数编码'])
            ->addColumn('showings_number', 'string', ['default' => '', 'null' => false, 'limit' => 20, 'comment' => '场次'])
            ->addColumn('is_append', 'enum', ['values' => 'yes,no', 'default' => 'no', 'comment' => '是否新增'])
            ->addColumn('enable', 'enum', ['values' => 'default,yes,no', 'default' => 'default', 'comment' => '默认,启用,废除(default,yes,no)'])
            ->addColumn('published', 'enum', ['values' => 'yes,no', 'default' => 'no', 'comment' => '是否发布过该实体'])
            ->addColumn('created_by', 'integer', ['signed' => false, 'null' => false, 'default' => 0, 'limit' => 11, 'comment' => '创建人'])
            ->addColumn('updated_by', 'integer', ['signed' => false, 'null' => false, 'default' => 0, 'limit' => 11, 'comment' => '更新人'])
            ->addColumn('json', 'json', ['null' => true, 'comment' => '存储自定义字段'])
            ->addColumn('created', 'integer', ['signed' => false, 'null' => false, 'default' => 0, 'limit' => 11, 'comment' => '创建时间'])
            ->addColumn('updated', 'integer', ['signed' => false, 'null' => false, 'default' => 0, 'limit' => 11, 'comment' => '更新时间']);
        $table->addIndex(['review_feedback_id', 'entity_id'], ['name' => 'idx_review_feedback_id_entity_id', 'type' => 'unique']);
        $table->create();

    }

    public function down()
    {
        $this->table('review_feedback_entity')->drop()->save();
    }
}
